HA$PBExportHeader$u_cst_mantocabedet.sru
forward
global type u_cst_mantocabedet from u_cst_tabpage
end type
type dw_5 from datawindow within u_cst_mantocabedet
end type
type dw_4 from datawindow within u_cst_mantocabedet
end type
type dw_3 from datawindow within u_cst_mantocabedet
end type
type st_det2 from statictext within u_cst_mantocabedet
end type
type st_det1 from statictext within u_cst_mantocabedet
end type
type st_titulo from statictext within u_cst_mantocabedet
end type
type dw_2 from datawindow within u_cst_mantocabedet
end type
type uo_toolbarstrip from u_cst_toolbarstrip within u_cst_mantocabedet
end type
type dw_1 from datawindow within u_cst_mantocabedet
end type
type uo_1 from u_cst_statictext within u_cst_mantocabedet
end type
end forward

global type u_cst_mantocabedet from u_cst_tabpage
integer width = 3067
integer height = 2120
event ue_mostrar ( powerobject ap_object,  boolean ab_tab,  integer ai_sw )
event type integer ue_grabar ( )
event ue_copy_fila ( datawindow ad_dw,  integer ai_row,  integer ai_sw )
event ue_grabar_previo ( )
event ue_nuevo ( )
event ue_ver_object ( boolean ab_ver )
event ue_editar ( )
event type long ue_getdwmodified ( )
event ue_ver_default ( )
event ue_settabtext ( string as_titulo )
event ue_copy_fila_det ( datawindow ad_dw,  integer ai_row,  integer ai_sw )
event ue_bloquear_dwdet ( )
event ue_setdwc ( )
event ue_setrow ( integer ai_row )
event ue_cancelar ( )
event ue_parametros ( )
event type boolean ue_grabar_error ( boolean ab_error )
event ue_grabar_pos ( )
event type boolean ue_grabar_otros ( )
event ue_agregar ( )
event ue_eliminar_detalle ( )
event ue_anular ( )
event ue_cambio_opc ( string as_button )
event ue_sumar ( )
event type integer ue_grabar_externo ( )
event ue_imprimir ( )
event ue_print ( )
event ue_tecla pbm_keydown
event ue_comprobante ( )
dw_5 dw_5
dw_4 dw_4
dw_3 dw_3
st_det2 st_det2
st_det1 st_det1
st_titulo st_titulo
dw_2 dw_2
uo_toolbarstrip uo_toolbarstrip
dw_1 dw_1
uo_1 uo_1
end type
global u_cst_mantocabedet u_cst_mantocabedet

type variables
s_parm istr_parm
boolean dw_has_focus
string is_error  ,is_button,is_tabla ,is_idcodigo,is_entidad,is_columna,is_tipocolumna,is_codigo,is_window  ,is_menu	,is_subdiario,is_diario,is_comprobante
long il_id ,il_error=0,il_codigo,il_idDocumento
integer ii_currentrow , ii_row,ii_sw,ii_idcodigo,ii_codigo,ii_window,ii_PrintRow,ii_PrintLength,ii_PrintWidth,ii_PrintMatricial
datastore ids_datastore
Window iw_parent
//u_cst_tabcontrol iuo_parent 
datawindowchild dwc ,dwc2
//datawindow idw_detalle
u_cst_powerdock uo_powerdock
userobject iuo_tab
u_cst_grillamaincabedet iuo_grillamain
u_cst_tabmantocabedet iuo_tabmantomain
end variables

forward prototypes
public function integer of_getwindow ()
public function integer of_getcolor (string as_color)
public function string of_getcodigo (string as_tabla)
public subroutine of_retrieve (long al_codigo)
public subroutine of_retrieve (integer ai_codigo)
public subroutine of_retrieve (string as_codigo)
public subroutine of_bloquear_columna (datawindow adw)
public function boolean of_verificar_datos_detalle ()
public function long of_getcodigoint (string as_tabla)
public subroutine of_buscar_dato (string as_campo)
end prototypes

event ue_mostrar(powerobject ap_object, boolean ab_tab, integer ai_sw);string ls_dw,ls_button,ls_entidad
long ll_codigo,ll_Rows

istr_parm        = ap_object
ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
uo_powerdock = istr_parm.auo_powerdock 
ls_button         = istr_parm.as_button
ls_dw              = ids_datastore.object.tDw1[1]
is_tabla           = ids_datastore.object.tTabla[1]
iuo_tab            = istr_parm.auo_userobject 
iuo_grillamain  = istr_parm.auo_grillamaincabedet
iuo_tabmantomain = istr_parm.auo_tabmantocabedet
is_idcodigo			=  istr_parm.as_parm[1] //id tabla
if ls_dw = '' or isnull(ls_dw) then return

is_button = ls_button
//if  ab_tab  then
dw_1.dataobject=ls_dw
dw_2.dataobject=ls_dw
dw_1.settransobject(sqlca)
dw_2.settransobject(sqlca)
//end if

//choose case upper(is_button)
//	case 'NUEVO'
//		dw_1.accepttext( ) //= -1  then return
//		ll_Rows = dw_1.ModifiedCount()
//		IF ll_Rows > 0 then
//			choose case f_msg('$$HEX1$$bf00$$ENDHEX$$Estas editando una empresa. $$HEX1$$bf00$$ENDHEX$$Quieres guardar los cambios?',5) 
//				case 3 //es cuando cancelas
//					return
//				case 2 //aqui es cuando no grabas y sales
//					dw_1.reset()
//					dw_1.insertrow( 0)
//					iuo_grillamain.event dynamic ue_dw_enabled(true)//activa para no poder modificar 
//				case 1 //aqui grabas y sales
//					 event ue_grabar( )
//					 uo_toolbarstrip.of_setenabled( 'Grabar', true)		
//					 uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//					 iuo_grillamain.event dynamic ue_dw_enabled(false,ll_Rows)
//					 //iuo_tabmantomain.event dynamic ue_enabled_object(true,0)
//					return
//			end choose
//		end if
//		uo_powerdock.of_setdocumenttext( iuo_tab ,'Nuevo / '+ is_tabla)
//		dw_1.reset()
//		dw_1.insertrow( 0)
//		dw_1.enabled= true
//		dw_1.visible = true
//		dw_2.visible = false
//		uo_toolbarstrip.visible = true
//		uo_toolbarstrip.of_setvisible( 'Grabar', true)
//		uo_toolbarstrip.of_setvisible( 'Cancelar', true)
//		uo_toolbarstrip.of_setvisible( 'Editar', false)
//		uo_toolbarstrip.of_setvisible( 'Borrar', false)
//		uo_toolbarstrip.of_setenabled( 'Grabar', true)		
//		uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//		iuo_grillamain.event dynamic ue_dw_enabled(true,ll_Rows)
//	//	iuo_tabmantomain.event dynamic ue_enabled_object(false,0)
//	CASE 'EDITAR'
//		dw_1.accepttext( ) //= -1  then return
////		ll_Rows = dw_1.ModifiedCount()
////		IF ll_Rows > 0  then
////			if f_msj('$$HEX1$$bf00$$ENDHEX$$Desa guardar los cambios que hizo al usuario?',2) = 2 then return
////		end if
//
//		uo_powerdock.of_setdocumenttext( iuo_tab ,'Editar / '+ is_tabla)
//		dw_1.retrieve(is_idcodigo) ;				commit;
//		dw_1.enabled= true
//		uo_toolbarstrip.of_setenabled( 'Grabar', true)		
//		uo_toolbarstrip.of_setenabled( 'Cancelar', TRUE)
////	CASE 'CONSULTAR'
////		dw_1.accepttext( )// = -1  then return
////		ll_Rows = dw_1.ModifiedCount()
////		IF ll_Rows > 0  then
////			if f_msj('$$HEX1$$bf00$$ENDHEX$$Desa guardar los cambios que hizo al usuario?',2) = 2 then return
////		end if
////		uo_powerdock.of_setdocumenttext( iuo_tab ,'Consultar / '+ is_tabla)
////		dw_1.retrieve(is_idcodigo) ; 	commit;
////		dw_1.enabled= false
////		uo_toolbarstrip.of_setenabled( 'Grabar', false)
////		uo_toolbarstrip.of_setenabled( 'Cancelar', false)
//END CHOOSE

end event

event type integer ue_grabar();integer li_return=1,li_fila,li_grabar_error
string ls_empresa
dwItemStatus 		l_status

if dw_1.accepttext( ) =  - 1  then return 0;if dw_3.accepttext( ) =  - 1  then return 0
If f_findrequired(dw_1) = -1 Then Return 0 ; If f_findrequired(dw_3) = -1 Then Return 0

choose case UPPER(is_button)
	case 'ANULAR'
		li_grabar_error=event ue_grabar_externo( )
		choose case li_grabar_error
			case 1 //ok 
				//this.event ue_Grabar_Pos()
				return 1
			case -1
				ROLLBACK USING SQLCA;
				return 0
		End choose 
END CHOOSE
	

//-- Verifica el detalle
If dw_3.RowCount() = 0 Then
	MessageBox('Advertencia','Error, No Existe Detalle',stopsign!)
	Return 0
End If

This.event ue_Grabar_Previo()

//-- Verifica los datos del detalle
If Not of_verificar_datos_detalle() Then
	ROLLBACK USING SQLCA;Return 0
End If

if dw_1.update(true,false) = 1 then
	//NO HUBO ERROR AL GRABAR
	if This.Event ue_Grabar_Error(false) then
		
		this.event post ue_Grabar_Pos()
		MessageBox('Informaci$$HEX1$$f300$$ENDHEX$$n','El Proceso de Grabaci$$HEX1$$f300$$ENDHEX$$n se Realizo Exitosamente',information!)
		return 1
	end if
	
else
	//ERROR EN GRABAR
	this.Event ue_Grabar_Error(TRUE) 
end if

return 0
end event

event ue_copy_fila(datawindow ad_dw, integer ai_row, integer ai_sw);long ll_rows
dw_1.reset() //cabecera
dw_2.reset(); dw_2.clear()
ii_sw =ai_sw
ii_row  = ai_row
dw_2.object.data = ad_dw.object.data

//dw_2.GetChild("iditem", dwc);dwc.reset()
//gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)
//event ue_setdwc()	
//dw_2.visible=true
event ue_settabtext( 'Consultar')

end event

event ue_grabar_previo();long ll_movimiento
integer li_fila

CHOOSE CASE UPPER(is_button)
	case 'NUEVO'
		
	case 'EDITAR'
		
END CHOOSE


end event

event ue_nuevo();is_button = 'Nuevo'
EVENT UE_CAMbio_opc( 'NUEVO')
dw_1.reset()
dw_3.reset()
dw_1.insertrow(0)
//dw_1.SetRedraw(FALSE)
//dw_1.setcolumn(2) ; dw_1.setfocus( )
//IF LEN(IS_TABLA) > 0  THEN dw_1.object.data[1,1] = of_getcodigo(is_tabla)

end event

event ue_ver_object(boolean ab_ver);boolean lb_sw

ab_ver = true 
lb_sw = false
//if ab_ver = false then lb_sw = true

//dw_1.enabled= ab_ver
//dw_3.enabled = ab_ver

uo_toolbarstrip.visible = true

choose case upper(is_button) 
	case 'NUEVO'
		uo_toolbarstrip.of_setvisible( 'Editar', lb_sw);uo_toolbarstrip.of_setvisible( 'Anular', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Grabar', ab_ver)// ; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', ab_ver)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', ab_ver)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', ab_ver)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
		dw_1.visible = ab_ver ; 		dw_3.visible = ab_ver ; 	dw_2.visible =lb_sw; 		dw_4.visible =lb_sw
	case 'EDITAR'
		dw_1.visible = ab_ver ; 		dw_3.visible = ab_ver ; 	dw_2.visible =lb_sw; 		dw_4.visible =lb_sw
		uo_toolbarstrip.of_setvisible( 'Editar', lb_sw);uo_toolbarstrip.of_setvisible( 'Anular', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Grabar', ab_ver) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', ab_ver)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', ab_ver)//; uo_toolbarstrip.of_setenabled( 'Agregar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', ab_ver)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', ab_ver)
	case 'ANULAR'
		dw_1.visible = lb_sw ; 		dw_3.visible = lb_sw ; 	dw_2.visible =ab_ver; 		dw_4.visible =ab_ver
		uo_toolbarstrip.of_setvisible( 'Editar', lb_sw);uo_toolbarstrip.of_setvisible( 'Anular', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Grabar', ab_ver)// ; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', ab_ver)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
	case 'CANCELAR'	
		
		uo_toolbarstrip.of_setvisible( 'Grabar', lb_sw) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = lb_sw ; 		dw_3.visible = lb_sw ; 	dw_2.visible = ab_ver; 		dw_4.visible =ab_ver
		uo_toolbarstrip.of_setvisible( 'Cancelar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Editar', ab_ver);
		uo_toolbarstrip.of_setvisible( 'Anular', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
	CASE 'CONSULTAR'
		uo_toolbarstrip.of_setvisible( 'Grabar', lb_sw) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = TRUE ; 		dw_3.visible = TRUE ; 	dw_2.visible = FALSE; 		dw_4.visible =FALSE
		uo_toolbarstrip.of_setvisible( 'Cancelar', TRUE)
//		uo_toolbarstrip.of_setvisible( 'Editar', ab_ver);
		//uo_toolbarstrip.of_setvisible( 'Anular', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
	CASE 'DEFAULT'
		dw_1.enabled= false ;	dw_1.visible = false ;		dw_2.visible = false ;		uo_1.visible = true
		uo_toolbarstrip.visible = false ;		st_titulo.visible = true ;		st_det1.visible = true
		event ue_settabtext( 'PRINCIPAL')
	case	else 
		uo_toolbarstrip.of_setvisible( 'Grabar', lb_sw) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = lb_sw ; 		dw_3.visible = lb_sw ; 	dw_2.visible = ab_ver; 		dw_4.visible =ab_ver
		uo_toolbarstrip.of_setvisible( 'Cancelar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Editar', ab_ver);
		uo_toolbarstrip.of_setvisible( 'Anular', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
end choose

//dw_1.visible = ab_ver
//dw_3.visible = ab_ver
////Consulta
//dw_2.visible =lb_sw
//dw_4.visible =lb_sw

//dw_2.enabled= ab_ver
//dw_4.enabled = ab_ver

//dw_4.vscrollbar = lb_sw
//if ab_ver = false then
//end if
//iuo_grillamain.event dynamic ue_dw_enabled(true,ll_Rows)
end event

event ue_editar();
iuo_tabmantomain.event ue_setbutton(is_button)
iuo_tabmantomain.event	ue_set_ib_sw(true)

iuo_grillamain.event ue_activa_opc( true)
event ue_settabtext ('Editar '+ is_entidad)
event ue_cambio_opc('EDITAR')
is_columna = dw_1.describe('#'+string(1)+'.name')
is_tipocolumna = dw_1.describe(is_columna+'.coltype')	

dw_3.GetChild("iditem", dwc);dwc.reset()
gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)

if left(is_tipocolumna,4)='char' then
	 is_codigo =dw_2.object.data[1,1]
	 of_retrieve( is_codigo)	
elseif is_tipocolumna='int' then
	 ii_codigo =dw_2.object.data[1,1]
	 of_retrieve( ii_codigo)	
else
	il_codigo =dw_2.object.data[1,1]
	 of_retrieve( il_codigo)	
end if		
end event

event type long ue_getdwmodified();dw_1.accepttext( ) //= -1  then return

long ll_count

ll_count =dw_1.ModifiedCount() + dw_3.ModifiedCount() + dw_3.deletedcount( )

return ll_count
end event

event ue_ver_default();boolean lb_sw
//if ab_ver = true then lb_sw = false
//if ab_ver = false then lb_sw = true

dw_1.enabled= false 
dw_1.visible = false
dw_2.visible = false
uo_1.visible = true
uo_toolbarstrip.visible = false
st_titulo.visible = true
st_det1.visible = true
//uo_toolbarstrip.of_setvisible( 'Grabar', false)
//uo_toolbarstrip.of_setvisible( 'Cancelar', false)
//uo_toolbarstrip.of_setvisible( 'Editar', false)
//uo_toolbarstrip.of_setvisible( 'Borrar', false)
//uo_toolbarstrip.of_setenabled( 'Grabar', false)		
//uo_toolbarstrip.of_setenabled( 'Cancelar', false)
//uo_toolbarstrip.of_setenabled( 'Agregar', false)
end event

event ue_settabtext(string as_titulo);


uo_powerdock.of_setdocumenttext( uo_powerdock.of_getactiveobject( ) ,as_titulo)


end event

event ue_copy_fila_det(datawindow ad_dw, integer ai_row, integer ai_sw);long ll_rows
INTEGER LI_ROW
dw_3.reset()
dw_4.reset(); dw_3.clear();dw_4.clear()
ii_sw =ai_sw
//ii_row  = ai_row

if ad_dw.rowcount() > 0 then
	dw_4.object.data = ad_dw.object.data
	dw_4.GetChild("iditem", dwc);dwc.reset()
	gdc_mitemalma1.RowsCopy(gdc_mitemalma1.GetRow(), gdc_mitemalma1.RowCount(), Primary!, dwc, 1, Primary!)
end if
event ue_setdwc()	
//dw_2.visible=true
//event ue_settabtext( 'Consultar')

end event

event ue_bloquear_dwdet();of_bloquear_columna( dw_4)
end event

event ue_setdwc();choose case is_tabla
	case 'MMOVIMIENTO'
			dw_2.GetChild("iddocu", dwc);dwc.reset();	dwc.settransobject( sqlca);	dwc.retrieve( )
			dw_2.GetChild("idtrans", dwc);dwc.reset();	dwc.settransobject( sqlca);	dwc.retrieve( )
			dw_2.GetChild("idalma", dwc);dwc.reset();	dwc.settransobject( sqlca);	dwc.retrieve( )
			dw_2.GetChild("idcentro", dwc);dwc.reset();	dwc.settransobject( sqlca);	dwc.retrieve( )
			
	case 'MITEM'
//			dw_2.GetChild("idtipoitem", dwc);dwc.reset()
//			dwc.settransobject( sqlca)
//			dwc.retrieve( )
//			
//			dw_2.GetChild("idgrupo", dwc);dwc.reset()
//			dwc.settransobject( sqlca)
//			dwc.retrieve( )
//			
//			
//			dw_2.GetChild("idfami", dwc);dwc.reset()
//			dwc.settransobject( sqlca)
//			dwc.retrieve( )
//			
//			dw_2.GetChild("idsubfami", dwc);dwc.reset()
//			dwc.settransobject( sqlca)
//			dwc.retrieve( )
	End Choose
commit;
end event

event ue_setrow(integer ai_row);ii_row=ai_row
end event

event ue_cancelar();
if	event ue_getdwmodified( ) > 0 then
	if f_msg('Cambio realizados ... $$HEX1$$bf00$$ENDHEX$$Esta seguro que desea cancelar ?',7) = 2 then return
end if
	
//if	UPPER(is_button) = 'NUEVO'  THEN
//	event ue_ver_default()
//	event ue_settabtext ('Principal')
//ELSE

event ue_cambio_opc(is_button)
//end if	

dw_1.reset();dw_3.reset( )
iuo_grillamain.event dynamic ue_activa_opc(false) 
iuo_grillamain.event dynamic ue_bloquear_refrescar(false) 
end event

event ue_parametros();window w_to_open
s_parm 				lstr_parm
istr_parm.auo_powerdock = uo_powerdock 
istr_parm.string_parm[1] = 'P'
//istr_parm.string_parm[1] = 'P'

if isnull(is_window) or len(is_window) = 0 then return
OpenWithParm(w_to_open, istr_parm,is_window)	
lstr_parm=message.powerobjectparm
if lstr_parm.char_parm = '1' then 
	iuo_grillamain.dynamic of_setparam(lstr_parm.integer_parm[1],lstr_parm.integer_parm[2],lstr_parm.integer_parm[3])
end if
//IF lstr_parm.char_parm[1]='1' THEN
//	idw_ficha.settext(lstr_parm.string_parm[4])
//	wf_obt_sucursal(lstr_parm.string_parm[2],lstr_parm.string_parm[4])
//END IF
end event

event type boolean ue_grabar_error(boolean ab_error);string ls_documento, ls_nro_oc

//ls_nro_oc = This.GetItemString(This.GetRow(),'cc_ordcom')
If Not ab_error Then
	//-- Actualiza el Detalle
	If dw_3.Update(true,false)=-1 Then
		Messagebox('Sistema','Error Actualizando Detalle...', StopSign!)
		RollBack;
		Return  FALSE
	End If
	//grabar otros procesos despues del grabado de la cabecera y detalle
	if not this.event ue_grabar_otros()  then return FALSE
	dw_2.reset();dw_4.reset();
	dw_1.RowsCopy(dw_1.GetRow(),dw_1.GetRow(), primary!, dw_2  , 1, Primary!)
	dw_3.RowsCopy(1,dw_3.Rowcount(), primary!, dw_4, 1, Primary!)
	dw_1.resetupdate();	dw_3.resetupdate(); 
	COMMIT USING SQLCA;
	iuo_grillamain.event dynamic ue_refrescar_row2(dw_2,dw_4,ii_row,is_button)
	
//	dw_1.reset();dw_3.reset( )
	Return TRUE
End If

ROLLBACK USING SQLCA;
//wf_menu_error_grabar()
MessageBox('Advertencia','Error al Grabar ',Stopsign!)
//idw_ficha.uf_protected('0',TRUE)
//idw_detalle.Event Dynamic ue_proteger('0')
Return FALSE
end event

event ue_grabar_pos();dw_4.GetChild("iditem", dwc);dwc.reset()
gdc_mitemalma1.RowsCopy(gdc_mitemalma1.GetRow(), gdc_mitemalma1.RowCount(), Primary!, dwc, 1, Primary!)
//dw_1.reset();dw_3.reset( )
iuo_grillamain.event ue_activa_opc( false)
this.event ue_cambio_opc('Consultar')
this.event ue_settabtext( 'Consultar')

dw_1.reset();dw_3.reset( )
iuo_grillamain.event dynamic ue_activa_opc(false) 
iuo_grillamain.event dynamic ue_bloquear_refrescar(false) 
this.event ue_setdwc()

//dw_4.GetChild("iditem", dwc);dwc.reset()
//gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)
////
////iuo_grillamain.event ue_activa_opc( false)
////iuo_grillamain.event dynamic ue_bloquear_refrescar(false) 
//////this.event ue_ver_object(true)
//this.event UE_CAMBIO_OPC('CONSULTAR')
////
//this.event ue_settabtext( 'Consultar')
////	iuo_tabmantomain.event dynamic ue_enabled_object(true,0)
end event

event type boolean ue_grabar_otros();Return true
end event

event ue_agregar();integer li_row

li_row =  dw_3.rowcount() 
dw_3.scrolltorow(dw_3.insertrow( 0))
if li_row = 0 then
	dw_3.object.idindice [1]=	1
else
	dw_3.object.idindice [dw_3.rowcount()]=	dw_3.object.idindice [li_row]+1
end if

dw_3.GetChild("iditem", dwc);dwc.reset()
gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)


//dw_3.object.idlista [dw_3.rowcount()]=dw_1.object.idlista[1]
//dw_3.object.iditem [dw_3.rowcount()]=1
//

//
//dw_3.object.ncant [dw_3.rowcount()]=1
//dw_3.object.nValorVta [dw_3.rowcount()]=1
//dw_3.object.nPrecioVta [dw_3.rowcount()]=1
//dw_3.object.bstat [dw_3.rowcount()]=1
////dw_1.object.idindice [dw_1.rowcount()]=dw_3.rowcount( )
end event

event ue_eliminar_detalle();integer li_fila
if dw_3.rowcount() = 0 then return
if f_msg('Esta seguro que desea eliminar este registro ??' + string(dw_3.getrow()), 2) = 2 then return 
dw_3.deleterow(0)
//for li_fila = 1 to dw_3.rowcount()
//	dw_3.object.idindice[li_fila]   =li_fila
//next
//

end event

event ue_anular();


iuo_tabmantomain.event ue_setbutton(is_button)
iuo_tabmantomain.event	ue_set_ib_sw(true)

iuo_grillamain.event ue_activa_opc( true)
event ue_settabtext ('Anular '+ is_entidad)
event ue_cambio_opc('ANULAR')
is_columna = dw_1.describe('#'+string(1)+'.name')
is_tipocolumna = dw_1.describe(is_columna+'.coltype')	

dw_3.GetChild("iditem", dwc);dwc.reset()
gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)

if left(is_tipocolumna,4)='char' then
	 is_codigo =dw_2.object.data[1,1]
	 of_retrieve( is_codigo)	
elseif is_tipocolumna='int' then
	 ii_codigo =dw_2.object.data[1,1]
	 of_retrieve( ii_codigo)	
else
	il_codigo =dw_2.object.data[1,1]
	 of_retrieve( il_codigo)	
end if		





end event

event ue_cambio_opc(string as_button);string ssas_button


choose case upper(as_button) 
	case 'NUEVO'
		uo_toolbarstrip.visible = TRUE
		uo_toolbarstrip.of_setvisible( 'Editar', FALSE);
		uo_toolbarstrip.of_setvisible( 'Anular', FALSE)
		uo_toolbarstrip.of_setvisible( 'Grabar', TRUE)// ; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', TRUE)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', TRUE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', TRUE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
		dw_1.visible = TRUE ; 		dw_3.visible = TRUE ; 	dw_2.visible =FALSE; 		dw_4.visible =FALSE
		dw_1.enabled = true ; dw_3.enabled=true
		event ue_settabtext( 'NUEVO')
	case 'EDITAR'
		uo_toolbarstrip.visible = TRUE
		dw_1.enabled = true ; dw_3.enabled=true
		dw_1.visible = true ; 		dw_3.visible = true ; 	dw_2.visible =false; 		dw_4.visible =false
		uo_toolbarstrip.of_setvisible( 'Editar', false);
		uo_toolbarstrip.of_setvisible( 'Anular', false)
		uo_toolbarstrip.of_setvisible( 'Grabar', true) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', true)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', true)//; uo_toolbarstrip.of_setenabled( 'Agregar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', true)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', ab_ver)
		event ue_settabtext( 'EDITAR')
	case 'ANULAR'
		uo_toolbarstrip.visible = TRUE
		dw_1.enabled = false ; dw_3.enabled=false
		dw_1.visible = true ; 		dw_3.visible = true ; 	dw_2.visible =false; 		dw_4.visible =false
		uo_toolbarstrip.of_setvisible( 'Editar', false);
		uo_toolbarstrip.of_setvisible( 'Anular', false)
		uo_toolbarstrip.of_setvisible( 'Grabar', true) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', true)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', false)//; uo_toolbarstrip.of_setenabled( 'Agregar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', false)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', ab_ver)
	case 'CANCELAR'	
		dw_1.enabled = false ; dw_3.enabled=false
		uo_toolbarstrip.of_setvisible( 'Grabar', FALSE) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		uo_toolbarstrip.of_setvisible( 'Cancelar', false)
		uo_toolbarstrip.of_setvisible( 'Editar', true);
		uo_toolbarstrip.of_setvisible( 'Anular', TRUE)
		uo_toolbarstrip.of_setvisible( 'Agregar', FALSE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', FALSE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
		event ue_settabtext( 'Consultar')
	CASE 'CONSULTAR'
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		dw_1.enabled = false; dw_2.enabled = false
		uo_toolbarstrip.visible = TRUE
		uo_toolbarstrip.of_setvisible( 'Grabar', FALSE) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		uo_toolbarstrip.of_setvisible( 'Cancelar', FALSE)
		uo_toolbarstrip.of_setvisible( 'Editar', true);
		uo_toolbarstrip.of_setvisible( 'Anular', true)
		uo_toolbarstrip.of_setvisible( 'Agregar', FALSE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', FALSE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
	CASE 'DEFAULT'
		dw_1.enabled= false ;	dw_1.visible = false ;		dw_2.visible = false ;		uo_1.visible = true
		uo_toolbarstrip.visible = false ;		st_titulo.visible = true ;		st_det1.visible = true
		event ue_settabtext( 'PRINCIPAL')
	case	else 
//		uo_toolbarstrip.of_setvisible( 'Grabar', lb_sw) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
//		dw_1.visible = lb_sw ; 		dw_3.visible = lb_sw ; 	dw_2.visible = ab_ver; 		dw_4.visible =ab_ver
//		uo_toolbarstrip.of_setvisible( 'Cancelar', lb_sw)
//		uo_toolbarstrip.of_setvisible( 'Editar', ab_ver);
//		uo_toolbarstrip.of_setvisible( 'Anular', ab_ver)
//		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
//		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
end choose

end event

event ue_sumar();integer li_fila
double ld_preciobase,ld_totalDocu
ld_totalDocu = 0 
for li_fila = 1 to dw_3.rowcount( )
	ld_preciobase = dw_3.Object.npreciobase[li_fila]
	dw_3.Object.ntotal[li_fila] = dw_3.Object.ncant[li_fila] * ld_preciobase
	ld_totalDocu = ld_totalDocu  + dw_3.Object.ntotal[li_fila]
next


dw_1.Object.ntotal[1] =ld_totalDocu
end event

event type integer ue_grabar_externo();return 0
end event

event ue_print();long ll_idDocumento
decimal {2} ld_cantPrint 
double ld_LengthCM
ll_idDocumento = dw_2.object.data[1,1]

if isnull(ii_PrintLength) or ii_PrintLength = 0  then ii_PrintLength = 140 // largo milimetros
if isnull(ii_PrintWidth) or ii_PrintWidth = 0  then ii_PrintWidth = 226 // ancho milimetros
if isnull(ii_PrintRow) or ii_PrintRow = 0  then ii_PrintRow = 15 // cant filas 
ld_cantPrint = ii_PrintRow
ld_LengthCM = ii_PrintLength / 10 //centometros

dw_5.retrieve(ll_idDocumento,ld_cantPrint) ; commit;
dw_5.Object.DataWindow.Print.Paper.Size = 256
dw_5.Object.DataWindow.Print.CustomPage.Length = ii_PrintLength
dw_5.Object.DataWindow.Print.CustomPage.Width  = ii_PrintWidth  //7 inches

if isnull(ii_PrintMatricial) then ii_PrintMatricial =0
if ii_PrintMatricial = 1 then
	f_printmatricialdw_main(ld_LengthCM,dw_5,'N')
else
	dw_5.print();
end if




//dw_5.dataobject  = 'd_usp_printdocuvta'
//dw_5.dataobject  = 'd_usp_printdocuvta_hnimportaciones'
//,ii_PrintRow,ii_PrintLength,ii_PrintWidth

end event

public function integer of_getwindow (); PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

public function integer of_getcolor (string as_color);Long ll_color
//
//CHOOSE CASE Upper(as_color)
//	CASE "BACKGROUND2"
//		CHOOSE CASE iuo_parent.il_CurrentTheme
//			CASE iuo_parent.BLUE
//				ll_color = RGB(129,169,226)
//			CASE iuo_parent.SILVER
//				ll_color = RGB(153,151,181)
//			CASE iuo_parent.OLIVE
//				ll_color = RGB(183,198,145)
//			CASE iuo_parent.CLASSIC
//				ll_color = RGB(213,210,202)
//		END CHOOSE
//END CHOOSE
//
RETURN ll_color
end function

public function string of_getcodigo (string as_tabla);string ls_codigo
//SQLCA.Usp_GetIdTabla(as_tabla,'')
ls_codigo  = Space(50)
sqlca.usp_getidtabla(as_tabla, ls_codigo)
return ls_codigo

end function

public subroutine of_retrieve (long al_codigo);dw_1.retrieve(al_codigo);
dw_3.retrieve(al_codigo); commit;
end subroutine

public subroutine of_retrieve (integer ai_codigo);dw_1.retrieve(ai_codigo); 
dw_3.retrieve(ai_codigo); commit;
end subroutine

public subroutine of_retrieve (string as_codigo);dw_1.retrieve(as_codigo)
dw_3.retrieve(as_codigo); commit;
end subroutine

public subroutine of_bloquear_columna (datawindow adw);//ddlb_1.reset( )
string ls_syntax, ls_cadena, ls_temp ,ls_columna,ls_cad
long ld_pos, ld_pos_ini, ld_pos_fin
Integer li_fila
ls_syntax = adw.Describe("DataWindow.Syntax")
/* Recupera el nombre de las columnas */
ld_pos = 1
ls_cadena = ''
li_fila =1
ls_cad ='.protect=1'
Do While ld_pos > 0
	
	ld_pos = pos(ls_syntax, 'text', ld_pos)
	If ld_pos > 0 Then
		ld_pos_ini = pos(ls_syntax, 'name=', ld_pos)
		ld_pos_fin = pos(ls_syntax, ' ', ld_pos_ini)
		ls_temp = ls_cadena +' '+ mid(ls_syntax, ld_pos_ini+5, ld_pos_fin - ld_pos_ini - 5 )
		If Right(ls_temp, 2)='_t' Then 	
//			li_fila = dw_1.InsertRow(0)
		
//			dw_1.Object.Columna_name[li_fila] = Trim(Left(ls_temp, Len(ls_temp)-2))
		ls_columna= Trim(Left(ls_temp, Len(ls_temp)-2))
		adw.modify(ls_columna+ls_cad)
//			ddlb_1.additem(Trim(Left(ls_temp, Len(ls_temp)-2)))	

			//-- las etiquetas
			ld_pos_ini = pos(ls_syntax, 'text="', ld_pos_fin)
			ld_pos_fin = pos(ls_syntax, '"', ld_pos_ini+7)
			
//			dw_1.Object.Columna_text[li_fila] = Trim(mid(ls_syntax, ld_pos_ini+6, ld_pos_fin - ld_pos_ini -6))
//			ddlb_1.additem(Trim(mid(ls_syntax, ld_pos_ini+6, ld_pos_fin - ld_pos_ini -6)))
			li_fila ++
		End If
			
		ld_pos = ld_pos_fin
	End If
Loop
//ddlb_1.selectitem( 1)
//ddlb_1.event selectionchanged(1)
Return


end subroutine

public function boolean of_verificar_datos_detalle ();long ll_fila
String ls_item

For ll_fila = 1 To dw_3.RowCount()
//	If idw_ficha.GetItemString(idw_ficha.GetRow(),'ci_tipped') <> '4' Then			//-- Articulos
//		//-- Valores ceros y nulos
//		If idw_detalle.GetItemDecimal(ll_fila,'nq_artic') = 0 Or &
//			idw_detalle.GetItemDecimal(ll_fila,'nm_precio') = 0 Then Return False
//	Else																								//-- Serivios
//		If idw_detalle.GetItemDecimal(ll_fila,'fq_servic') = 0 Or &
//			idw_detalle.GetItemDecimal(ll_fila,'fm_precio') = 0 Then Return False
//	End If
//	
//	//-- Actualiza el numero de oc
//	idw_detalle.SetItem(ll_fila,'cc_ordcom', idw_ficha.object.cc_ordcom[1])

Next

Return True
end function

public function long of_getcodigoint (string as_tabla);long li_codigo
//SQLCA.Usp_GetIdTabla(as_tabla,'')
li_codigo  = 0
sqlca.usp_getidtablaint(as_tabla, li_codigo )
return li_codigo

end function

public subroutine of_buscar_dato (string as_campo);
end subroutine

on u_cst_mantocabedet.create
int iCurrent
call super::create
this.dw_5=create dw_5
this.dw_4=create dw_4
this.dw_3=create dw_3
this.st_det2=create st_det2
this.st_det1=create st_det1
this.st_titulo=create st_titulo
this.dw_2=create dw_2
this.uo_toolbarstrip=create uo_toolbarstrip
this.dw_1=create dw_1
this.uo_1=create uo_1
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.dw_5
this.Control[iCurrent+2]=this.dw_4
this.Control[iCurrent+3]=this.dw_3
this.Control[iCurrent+4]=this.st_det2
this.Control[iCurrent+5]=this.st_det1
this.Control[iCurrent+6]=this.st_titulo
this.Control[iCurrent+7]=this.dw_2
this.Control[iCurrent+8]=this.uo_toolbarstrip
this.Control[iCurrent+9]=this.dw_1
this.Control[iCurrent+10]=this.uo_1
end on

on u_cst_mantocabedet.destroy
call super::destroy
destroy(this.dw_5)
destroy(this.dw_4)
destroy(this.dw_3)
destroy(this.st_det2)
destroy(this.st_det1)
destroy(this.st_titulo)
destroy(this.dw_2)
destroy(this.uo_toolbarstrip)
destroy(this.dw_1)
destroy(this.uo_1)
end on

event constructor;call super::constructor;string ls_dw3,ls_dw2,ls_opc,ls_dw,ls_user
long ll_codigo

istr_parm = message.powerobjectparm 

uo_toolbarstrip.visible = false
dw_1.visible = false
of_getwindow()

ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
is_menu = ids_datastore.object.idmenu[1]
is_subdiario = ids_datastore.object.idsubdiario[1]
uo_powerdock = istr_parm.auo_powerdock 
is_button         = istr_parm.as_button
ls_dw              = ids_datastore.object.tDw1[1]
ls_dw2              = ids_datastore.object.tDw2[1]
ls_dw3             = ids_datastore.object.tDw3[1]
is_tabla           = ids_datastore.object.tTabla[1]
is_window  					   = ids_datastore.object.twindow[1]
ii_window  					   = ids_datastore.object.bwindow[1]
ii_PrintRow =ids_datastore.object.nrowprint[1]
ii_PrintLength=ids_datastore.object.nLength[1]
ii_PrintWidth=ids_datastore.object.nWidth[1]
ii_PrintMatricial =ids_datastore.object.bPrintMatricial[1]

if isnull(ls_dw3) then ls_dw3 ='d_usp_printdocuvta'
is_entidad = ids_datastore.object.tEntidad[1]
if isnull(is_entidad) then is_entidad=''
iuo_tab            = istr_parm.auo_userobject 
iuo_grillamain  = istr_parm.auo_grillamaincabedet
iuo_tabmantomain = istr_parm.auo_tabmantocabedet
is_idcodigo			=  istr_parm.as_parm[1] //id tabla
if ls_dw = '' or isnull(ls_dw) then return

dw_1.dataobject=ls_dw //cabecera
dw_3.dataobject=ls_dw2//detalle
dw_1.settransobject(sqlca)
dw_3.settransobject(sqlca)
dw_2.dataobject=ls_dw
dw_4.dataobject=ls_dw2
dw_5.dataobject=ls_dw3
dw_5.settransobject(sqlca)
//limpiar
dw_1.reset();dw_3.reset()
dw_2.reset();dw_4.reset()
st_titulo.text = ids_datastore.object.tTitulo[1]
st_det1.text = ids_datastore.object.tObse1[1]
st_det2.text = ids_datastore.object.tObse2[1]
il_error =0
//uo_1.of_BackColor2(of_GetColor("BACKGROUND2"))
uo_1.of_BackColor2(RGB(129,169,226))
f_dataload('MITEMALMA')
//event post ue_settabtext ('')
//EVENT ue_mostrar (istr_parm,true,0)



end event

event resize;call super::resize;uo_toolbarstrip.Width =(this.width - 12) 
//DW_1.Resize(Width, Height  )
DW_2.Resize(Width, Height  )
DW_3.Resize(Width, Height  )
DW_4.Resize(Width, Height  )
uo_1.Resize(newWidth, newHeight)
dw_1.width = newwidth
dw_2.width = newwidth
dw_3.width = newwidth
dw_4.width = newwidth


DW_3.HEight =NEWHeight - (uo_toolbarstrip.Height + DW_1.Height + 20)
DW_4.HEight =NEWHeight - (uo_toolbarstrip.Height + DW_1.Height + 20)
end event

event ue_postconstructor;call super::ue_postconstructor;//choose case upper(is_button)
//	case 'NUEVO'
//		  uo_toolbarstrip.of_setenabled( 'Grabar', true)	
//		  uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//		  dw_1.setcolumn( 4)
//		  dw_1.setfocus( )
//		 
//	case 'EDITAR'
//		 uo_toolbarstrip.of_setenabled( 'Grabar', true)	
//		 uo_toolbarstrip.of_setenabled( 'Cancelar', true)
//		 dw_1.setcolumn( 4)
//		 dw_1.setfocus( )
// case 'CONSULTAR'
//		 uo_toolbarstrip.of_setenabled( 'Grabar', FALSE)		
//		uo_toolbarstrip.of_setenabled( 'Cancelar', false)
//End choose 
//
end event

type dw_5 from datawindow within u_cst_mantocabedet
boolean visible = false
integer x = 530
integer y = 1848
integer width = 320
integer height = 204
integer taborder = 40
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_4 from datawindow within u_cst_mantocabedet
boolean visible = false
integer x = 5
integer y = 684
integer width = 3058
integer height = 1436
integer taborder = 30
string title = "none"
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_3 from datawindow within u_cst_mantocabedet
event ue_proteger ( string as_proteger )
event ue_enter pbm_dwnprocessenter
event type integer ue_dropdowndw ( )
event ue_tecla pbm_dwnkey
event ue_updaterow ( integer ai_fila )
event ue_postevent ( integer ai_check,  string as_tipo )
boolean visible = false
integer y = 684
integer width = 3067
integer height = 1404
integer taborder = 20
string title = "none"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event ue_proteger(string as_proteger);integer li_indice
string  ls_modify

for li_indice=1 to integer(this.object.datawindow.column.count)
	 ls_modify="#" + string(li_indice) + ".protect=" + as_proteger
	 This.modify(ls_modify)
next

end event

event ue_enter;Send( Handle( this ), 256, 9, Long( 0, 0 ) ) // Send message for processing TAB key 
return 1 
end event

event ue_tecla;choose case key			
	
	case KeyF1!		
		
end choose
end event

event constructor;dw_3.setrowfocusindicator( hand!)
end event

event dberror;f_msg(sqlerrtext,4)
return 1 
end event

type st_det2 from statictext within u_cst_mantocabedet
integer x = 32
integer y = 244
integer width = 1824
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 16777215
boolean focusrectangle = false
end type

type st_det1 from statictext within u_cst_mantocabedet
integer x = 32
integer y = 144
integer width = 1824
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 16777215
string text = "* Selecciona un contacto para ver o editar sus datos"
boolean focusrectangle = false
end type

type st_titulo from statictext within u_cst_mantocabedet
integer x = 37
integer y = 24
integer width = 1819
integer height = 80
integer textsize = -12
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 8388608
long backcolor = 16777215
string text = "Empresas:"
boolean focusrectangle = false
end type

type dw_2 from datawindow within u_cst_mantocabedet
boolean visible = false
integer x = 5
integer y = 112
integer width = 3058
integer height = 584
integer taborder = 20
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type uo_toolbarstrip from u_cst_toolbarstrip within u_cst_mantocabedet
boolean visible = false
integer width = 3067
integer taborder = 20
end type

on uo_toolbarstrip.destroy
call u_cst_toolbarstrip::destroy
end on

event ue_buttonclicked;call super::ue_buttonclicked;string ls_columna,ls_tipo,ls_codigo
integer li_codigo
long ll_codigo,ll_opc


choose case upper(as_button)
	case 'ANULAR'
		is_button = as_button
		event ue_anular()
	case 'ELIMINAR FILA'
		EVENT ue_eliminar_detalle()
	case 'AGREGAR'
		//FOR ll_codigo = 1 to 10000
			event ue_agregar()
		//next
	case 'EDITAR'
			is_button = as_button
			event ue_editar()
	case 'GRABAR'
		event  ue_grabar( )
	case 'CANCELAR'
		
	   if upper(is_button) ='NUEVO' then 
			is_button ='DEFAULT'
		ELSE
			is_button ='CANCELAR'
	   end if	
	  // is_button = as_button
       event ue_cancelar()
	//  event ue_settabtext( 'PRINCIPAL')	
		//	iuo_tab.event dynamic ue_enabled_object(true)
		//	case 'SALIR'
		//	uo_powerdock.of_closedocument(uo_powerdock.of_getactiveobject( ))
END CHOOSE
end event

event constructor;call super::constructor;
this.of_AddItem('Grabar', 'Save!')
this.of_AddItem('Editar', gs_unidad+'\IMG\ICO\edit.ico')
this.of_AddItem('Anular', gs_unidad+'\IMG\ICO\Error.ico')
this.of_AddItem('Agregar', 'Insert5!')
this.of_AddItem('Eliminar Fila', 'DeleteRow!')
this.of_AddItem('Cancelar', 'Undo!')
this.of_AddItem('Imprimir', 'Print!')

//opciones en estado invisible
this.of_setvisible( 'Grabar', false)
this.of_setvisible( 'Agregar', false)
this.of_setvisible( 'Eliminar Fila', false)
this.of_setvisible( 'Cancelar', false)
this.of_setvisible('Imprimir', false)
//esto es para mostar los textos
this.of_DisplayText(true)



end event

event ue_tecla;call super::ue_tecla;if key = KeyF1!  then
	f_msj('hola Fabio',1)
end if
end event

type dw_1 from datawindow within u_cst_mantocabedet
event ue_enter pbm_dwnprocessenter
event ue_setcolor ( long al_color )
event ue_tecla pbm_dwnkey
integer y = 108
integer width = 3072
integer height = 580
integer taborder = 10
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event ue_enter;Send( Handle( this ), 256, 9, Long( 0, 0 ) ) // Send message for processing TAB key 
return 1 
end event

event ue_setcolor(long al_color);integer li_columna,li_index
string  ls_columna,ls_Required,ls_style

li_columna = integer(this.Object.DataWindow.Column.Count)

for li_index=1 to li_columna
	
	  ls_Columna="#" + string(li_index) + ".name"
	 //Nombre de la Columna
	 Ls_Columna=This.Describe(Ls_Columna)
	 //Estilo de Edicion
	 ls_Style=Ls_Columna + ".edit.style"
	 Ls_Style=lower(This.Describe(Ls_Style))
	 
	 CHOOSE CASE Ls_Style
		CASE 'dddw'
			Ls_Required=lower(This.Describe(Ls_Columna + ".dddw.Required"))
		CASE 'ddlb'
			Ls_Required=lower(This.Describe(Ls_Columna + ".ddlb.Required")			)
		CASE 'edit'
			Ls_Required=lower(This.Describe(Ls_Columna + ".edit.Required"))
		CASE 'editmask'
			Ls_Required=lower(This.Describe(Ls_Columna + ".editmask.Required"))
		CASE ELSE
			Continue
	 END CHOOSE
	 
	 If Ls_Required='yes' Then
		Ls_Columna=Ls_Columna + '.Background.Color=' + string(al_color)
		This.Modify(Ls_Columna)
	 End If
	 
next
end event

event itemchanged;//uo_toolbarstrip.of_setenabled( 'Grabar', true)	
this.accepttext( )
Choose Case dwo.name

	Case 'idmenu'
		If Trim(data) = '' Or IsNull(data) Then
			is_error = 'Error, Digite un C$$HEX1$$f300$$ENDHEX$$digo Valido'
			Return 1
		End If
End choose 
end event

event itemerror;

Choose Case dwo.name
	case 'idmenu'
		MessageBox('Advertencia','ingrese el menu',stopsign!)
	Case 'idprefil'
		MessageBox('Advertencia','ingrese el perfil',stopsign!)
//	      MessageBox('Advertencia',is_error,Stopsign!)
	Case 'cc_locac','cc_almac','ci_tipart'
//		MessageBox('Advertencia',is_error,stopsign!)
	Case 'cc_docum','cn_docum'
//		MessageBox('Advertencia',is_error,stopsign!)
End Choose
il_error =1
Return 1
end event

event constructor;event ue_setcolor(rgb(27,208,228))
end event

event rowfocuschanged;//dwitemstatus ldwitemstatus
//
//if currentrow < 1 then return
//
////if ib_lista or ib_tablist then return
//
//ldwitemstatus=this.getitemstatus(this.rowcount(),0,primary!)
//
//if ldwitemstatus=new! or ldwitemstatus=newmodified! then
//	this.scrolltorow(this.rowcount())
//	return
//end if
//
//if ii_currentrow=0 then ii_currentrow=currentrow
//this.selectrow(ii_currentrow,FALSE)
//this.selectrow(currentrow,TRUE)
//this.setrow(currentrow)
//ii_currentrow=currentrow
//
end event

type uo_1 from u_cst_statictext within u_cst_mantocabedet
integer width = 3077
integer height = 2112
integer taborder = 20
long backcolor = 16777215
boolean #vgradientfill = true
end type

on uo_1.destroy
call u_cst_statictext::destroy
end on

